package leetcode_201_300;

import java.util.ArrayList;
import java.util.List;

public class LeeCode_279_2 {
    public static void main(String[] args) {
        System.out.println(numSquares(13));
        System.out.println(numSquares(12));
        System.out.println(numSquares(43));
    }
    private static int numSquares(int n) {
        int[] dp = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            int minn = Integer.MAX_VALUE;
            for (int j = 1; j * j <= i; j++) {
                minn = Math.min(minn, dp[i - j * j]);
            }
            dp[i] = minn + 1;
        }
        return dp[n];
    }
}
